package com.yxh.adapter;

import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yxh.R;
import com.yxh.dto.LessonItemDto;

@SuppressLint("InflateParams") 
public class HomeClassAdapter extends BaseAdapter {

	private List<LessonItemDto> list;
	private LayoutInflater inflater;

	public HomeClassAdapter(Context context, List<LessonItemDto> list) {
		this.list = list;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public LessonItemDto getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.fragment_home_list_item,
					null);
			holder = new ViewHolder();
			holder.img = (ImageView) convertView.findViewById(R.id.img1);
			holder.tv = (TextView) convertView.findViewById(R.id.tv);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		LessonItemDto dto = list.get(position);
//		LogUtil.e("dto.title -->" + dto.title);
		if (!TextUtils.isEmpty(dto.title)) {
			holder.tv.setText(dto.title);
		}
		
		if ("1".equals(dto.topStory)) {
			holder.img.setBackgroundResource(R.drawable.main_home_bottom_icon_bg1);
		}else{
			holder.img.setBackgroundResource(R.drawable.main_home_bottom_icon_bg2);
		}
		
		return convertView;
	}

	static class ViewHolder {
		ImageView img;
		TextView tv;

	}

}
